#!/bin/bash
# jiyin@redhat.com

export LANG=C
P=${0##*/}

[[ $# = 0 ]] && {
	echo "Usage $P J:12345 [J:23456 ...] " >&2
	exit 1
}

jobList="$@"

: <<COMM
bkr job-results --prettyxml "$@" |
	sed -rn '/<recipeSet/,/<\/recipeSet>/ {
		/.*<recipeSet id="([0-9]+)".*/ {
			s//\nRS:\1/;p
		};

		/.*<recipe arch="([^"]+)" .*status="([^"]+)".*/ {
			s//    \1-\2/;p}
	};'


: <<COMM
for J in $jobList; do
	xq '.job.recipeSet | ."@id", (..|."@arch"? //empty)' <(bkr job-results --prettyxml $J) | xargs
	echo
done
COMM

for J in $jobList; do
	bkr job-results --prettyxml $J | xmllint --xpath '//recipeSet/@id | //recipe/@arch' -
	echo
done
echo

